#ifndef _HD_H_
#define _HD_H_

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "core.h"
//#include "ex.h"
#include "init.h"
//#include "error.h"
//#include "config.h"
//*********************************************
//
//                  display
//
//*********************************************
#define rck_on PORTC|=0b00000010
#define rck_off PORTC&=0b11111101
#define sck_on PORTC|=0b00000100
#define sck_off PORTC&=0b11111011
#define si_on PORTC|=0x01
#define si_off PORTC&=0xfe
#define sizeof_char 8
#define dis_n 4
#define led1_on PORTD&=0b01111111
#define led2_on PORTD&=0b10111111
#define led1_off PORTD|=0b10000000
#define led2_off PORTD|=0b01000000
#define table(num) pgm_read_byte(flash_table+(num))
#define point1_on array_dis[0]|=0b10000000
#define point2_on array_dis[1]|=0b10000000
#define point3_on array_dis[2]|=0b10000000
#define point4_on array_dis[3]|=0b10000000
#define points_on point2_on
extern unsigned char point_on;
//extern void turn_10(unsigned int value);
extern void turn_add(unsigned int value);
extern void ad_off(unsigned char a);
extern void dis_led(void);
extern void display_clear(void);
extern void display(void);
extern void key_dis(void);

//*******************************************************
//
//                         key
//
//*******************************************************
/*#define keynow (((~PIND)>>5) & 0x07)
#define keyNumber 3
#define key1 0x08
#define key2 0x04
#define key3 0x02
#define key4 0x01*/
#define keyNumber 3
#define key1 ((PINC&0b00001000)>>3)
#define key2 ((PINB&0b00000010)>>1)
#define key3 ((PINB&0b00000001)>>0)
extern unsigned char key_short;// 0 key4 1 key3 2 key2 3key1
extern unsigned char key_long;
extern unsigned char key_cont;
extern uint8_t Trg;
extern unsigned char Cont;
extern void g_key(void);




#define AM2301_High PORTD |= 0b00001000
#define AM2301_Low PORTD &= 0b11110111
#define AM2301_Bit PIND & 0b00001000
#define AM2301_Output DDRD |= 0b00001000
#define AM2301_Input DDRD &= 0b11110111
extern uint8_t AM2301_ReadByte(uint8_t *pData);
extern void AM2301_Data(void);





extern void rf(void);
#define MOSI_on PORTB|=0b00001000
#define MOSI_off PORTB&=0b11110111
#define MSCK_on PORTB|=0b00100000
#define MSCK_off PORTB&=0b11011111
#define MISO_s (PINB&0b00010000)>>4
#define CSN_on PORTD|=0b00000001
#define CSN_off PORTD&=0b11111110
#define CE_on PORTD|=0b00000010
#define CE_off PORTD&=0b11111101
#define IRQ_s PIND&0b00000100//(PIND&0b00000100)>>2


#define TX_ADR_WIDTH    5   // 5 bytes TX(RX) address width
#define RX_PLOAD_WIDTH  5  // 16 bytes TX payload
#define TX_PLOAD_WIDTH  10  // 16 bytes TX payload
#define add_dev 0x01  //local address


//****************************************************************//
// SPI(nRF24L01) commands
#define READ_REG        0x00  // Define read command to register
#define WRITE_REG       0x20  // Define write command to register
#define RD_RX_PLOAD     0x61  // Define RX payload register address
#define WR_TX_PLOAD     0xA0  // Define TX payload register address
#define FLUSH_TX        0xE1  // Define flush TX register command
#define FLUSH_RX        0xE2  // Define flush RX register command
#define REUSE_TX_PL     0xE3  // Define reuse TX payload register command
//#define NOP             0xFF  // Define No Operation, might be used to read status register

//***************************************************//
// SPI(nRF24L01) registers(addresses)
#define CONFIG          0x00  // 'Config' register address
#define EN_AA           0x01  // 'Enable Auto Acknowledgment' register address
#define EN_RXADDR       0x02  // 'Enabled RX addresses' register address
#define SETUP_AW        0x03  // 'Setup address width' register address
#define SETUP_RETR      0x04  // 'Setup Auto. Retrans' register address
#define RF_CH           0x05  // 'RF channel' register address
#define RF_SETUP        0x06  // 'RF setup' register address
#define STATUS          0x07  // 'Status' register address
#define OBSERVE_TX      0x08  // 'Observe TX' register address
#define CD              0x09  // 'Carrier Detect' register address
#define RX_ADDR_P0      0x0A  // 'RX address pipe0' register address
#define RX_ADDR_P1      0x0B  // 'RX address pipe1' register address
#define RX_ADDR_P2      0x0C  // 'RX address pipe2' register address
#define RX_ADDR_P3      0x0D  // 'RX address pipe3' register address
#define RX_ADDR_P4      0x0E  // 'RX address pipe4' register address
#define RX_ADDR_P5      0x0F  // 'RX address pipe5' register address
#define TX_ADDR         0x10  // 'TX address' register address
#define RX_PW_P0        0x11  // 'RX payload width, pipe0' register address
#define RX_PW_P1        0x12  // 'RX payload width, pipe1' register address
#define RX_PW_P2        0x13  // 'RX payload width, pipe2' register address
#define RX_PW_P3        0x14  // 'RX payload width, pipe3' register address
#define RX_PW_P4        0x15  // 'RX payload width, pipe4' register address
#define RX_PW_P5        0x16  // 'RX payload width, pipe5' register address
#define FIFO_STATUS     0x17  // 'FIFO Status Register' register address
#define 	MAX_RT  		0x10  	// Max #of TX retrans interrupt
#define 	TX_DS   		0x20  	// TX data sent interrupt
#define 	RX_DR   		0x40  	// RX data received

#endif




